﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BLL.BusinessClasses;

namespace WebSite.Egresado
{
    public partial class VerEmpresas : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["UsuarioDeSesion"] == null || !(this.Session["UsuarioDeSesion"] is UsuarioUniversitario))
            {
                this.Response.Redirect(@"~/General/Principal.aspx");
                return;
            }
            if (!(this.Page.IsPostBack))
            {
                this.DarBienvenida();
            }
        }

        protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Retrieve the GridView control in the second column.                
                if (((string)DataBinder.Eval(e.Row.DataItem, "Foto")) != null)
                {
                    ((Image)e.Row.FindControl("Image_Logo")).ImageUrl = ((string)DataBinder.Eval(e.Row.DataItem, "Foto"));
                }
                else
                {
                    ((Image)e.Row.FindControl("Image_Logo")).ImageUrl = "~\\Pictures\\CompanyPictures\\DefaultCompanyPic.png";
                }
            }
        }

        private void DarBienvenida()
        {
            ((Label)(this.Master.FindControl("Label_Bienvenida"))).Text = "Bienvenido <u>" +
                                                                          ((UsuarioUniversitario)this.Session["UsuarioDeSesion"]).PrimerNombre + " " +
                                                                          ((UsuarioUniversitario)this.Session["UsuarioDeSesion"]).PrimerApellido + "</u>";
        }

        protected void Button_LogOff_Click(object sender, EventArgs e)
        {
            this.Session["UsuarioDeSesion"] = null;

            this.Response.Redirect(@"~/General/Principal.aspx");
        }        
    }
}
